package com.snack.controller;

import com.snack.common.result.Result;
import com.snack.entity.dto.OrderDTO;
import com.snack.entity.pojo.Member;
import com.snack.entity.pojo.Order;
import com.snack.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangfuhao
 * @Date 2025/3/30
 */
@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 生成订单
     * @param orderDTO
     * @return
     */
    @RequestMapping("/addOrder")
    public Result addOrder(@RequestBody OrderDTO orderDTO){
        //记录订单以及订单跟随的零食列表
        return orderService.addOrder(orderDTO);
    }

    /**
     * 查询订单列表
     * @param order
     * @return
     */
    @RequestMapping("/listOrder")
    public Result listOrder(@RequestBody Order order){
        //列出订单以及订单跟随的零食列表
        return orderService.listOrder(order);
    }


    @RequestMapping("/getOrderDetails")
    public Result getOrderDetails(@RequestBody Order order){
        //查询订单详情
        return orderService.getOrderDetails(order);
    }

    @RequestMapping("/listOrdersByConsumerPhone")
    public Result listOrdersByConsumerPhone(@RequestBody Member member){
        //查询用户订单
        return orderService.listOrdersByConsumerPhone(member);
    }

    //过期库存销毁功能
    @RequestMapping("/deleteInventory")
    public Result deleteInventory(@RequestBody OrderDTO orderDTO){
        return orderService.deleteInventory(orderDTO);
    }

    //订单删除功能
    @RequestMapping("/deleteOrder")
    public Result deleteOrder(@RequestBody Order order){
        return orderService.deleteOrder(order);
    }
}
